﻿using Kooboo.CMS.Common.Runtime.Dependency;
using Kooboo.CMS.Sites.Extension.UI;
using Kooboo.CMS.Sites.Extension.UI.TopToolbar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using Kooboo.Web.Mvc;

namespace DemoModule.UI
{
    [Dependency(typeof(IToolbarProvider), Key = "DemoModule.UI.TestButtonToolbar")]
    public class TestButtonToolbar : IToolbarProvider
    {
        /// <summary>
        /// 按钮要在哪里显示
        /// 我们这里是要在Article这个Folder中显示
        /// 可以有多个地方，这里是个数组
        /// </summary>
        public MvcRoute[] ApplyTo
        {
            get
            {
                return new[]
                {
                    new MvcRoute
                    {
                        Action = "Index",
                        Controller = "TextContent",
                        Area = "Contents",
                        RouteValues = new Dictionary<string, object>
                        {
                            {"FolderName", "Article"}//这里我们可以加条件，比如我想让他在Article显示，Category中不显示
                        }
                    },
                    new MvcRoute
                    {
                        Action = "Diagnosis",
                        Controller = "System",
                        Area = "Sites",
                        RouteValues = null //这里假设我不添加条件，当然你可以指定站点之类的，跟上面那个类似的做法
                    }
                };
            }
        }

        public IEnumerable<ToolbarButton> GetButtons(RequestContext requestContext)
        {
            List<ToolbarButton> buttons = new List<ToolbarButton>();
            ToolbarButton testButton = new ToolbarButton
            {
                CommandTarget = new MvcRoute  //按钮点击后连接到哪里
                {
                    Action = "Index",
                    Controller = "MyTest",
                    Area = "DemoModule", //我们需要把这个拓展module注册为mvc的area
                    RouteValues = new Dictionary<string, object>
                    {
                        {"id",DateTime.Now.ToString("yyyy-MM-dd")} //参数
                    }
                },
                CommandText = "TestButton", //按钮显示文本
                GroupName = "MyGroup",
                HtmlAttributes = new Dictionary<string, object>
                {
                    {"target","_blank"} //假设在新页面中打开
                }
            };
            buttons.Add(testButton);
            return buttons;
        }

        public IEnumerable<ToolbarGroup> GetGroups(RequestContext requestContext)
        {
            ToolbarGroup group = new ToolbarGroup()
            {
                DisplayText = "My Group",
                GroupName = "MyGroup",
                IconClass = "add",
                Order = 0 //排序
            };
            return new List<ToolbarGroup>
            {
                group
            };
        }
    }
}
